#!/bin/bash
export MSYS_NO_PATHCONV=1
# Name of container to use for start the indy cli or bash
export BASH_CONTAINER=${BASH_CONTAINER:= nodejs_alice_1}
# Services to start for "up" - normally blank to start all services
export START_SERVICES=${START_SERVICES:=""}

# =================================================================================================================
# Usage:
# -----------------------------------------------------------------------------------------------------------------
usage () {
  cat <<-EOF

  Usage: $0 [command] [options]

  Commands:

  build - Build the docker images for the project.
          You need to do this first.

  up - Starts all containers and docker-compose logs.
       Use ctrl-c to exit logging. Use "down" or "stop" to stop the run.
  start - same as up

  logs - Display the logs from the docker compose run (ctrl-c to exit).

  bash - Start client container in a bash shell in /home/indy.

  cli - Start indy-cli in the agent container.

  down - Brings down the services and removes the volumes (storage).  The containers
         are not deleted so they will be reused the next time you run start.
  rm - same as down

  stop - Stops the containers, leaving the volumes (storage).

  rebuild - Force a full rebuild of the docker images (no cache)
EOF
exit 1
}

case "$1" in
  start|up)
      docker-compose up -d ${START_SERVICES}
      docker-compose logs -f
    ;;
  cli)
      docker exec -it -e MODE=cli  ${BASH_CONTAINER} indy-cli
    ;;
  bash)
       docker exec -it -e MODE=cli ${BASH_CONTAINER} bash
    ;;
  build)
      docker-compose build
    ;;
  rebuild)
      docker-compose build --no-cache
    ;;
  logs)
    docker-compose logs -f
    ;;
  stop)
    docker-compose stop
    ;;
  down|rm)
    docker-compose down -v
    ;;
  *)
      usage;;
esac
